package com.wenchao.quickstart.widget;

import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.webkit.WebChromeClient;
import android.widget.TextView;

import com.tencent.smtt.sdk.WebSettings;
import com.tencent.smtt.sdk.WebSettings.LayoutAlgorithm;
import com.tencent.smtt.sdk.WebView;
import com.tencent.smtt.sdk.WebViewClient;

/**
 * @author zhangwenchao
 */
public class X5WebView extends WebView {

    private WebViewClient client = new WebViewClient() {
        /**
         * 防止加载网页时调起系统浏览器
         */
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
    };

    public X5WebView(Context arg0) {
        this(arg0, null);
    }

    public X5WebView(Context arg0, AttributeSet arg1) {
        this(arg0, arg1, 0);
    }

    public X5WebView(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        setBackgroundColor(85621);
        this.setWebViewClient(client);
        // this.setWebChromeClient(chromeClient);
        // WebStorage webStorage = WebStorage.getInstance();
        initWebViewSettings();
        this.getView().setClickable(true);
    }

    private void initWebViewSettings() {
        WebSettings webSetting = this.getSettings();
        webSetting.setJavaScriptEnabled(true);
        webSetting.setJavaScriptCanOpenWindowsAutomatically(true);
        webSetting.setAllowFileAccess(true);
        //  webSetting.setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS);
        // 是否支持缩放
        // webSetting.setSupportZoom(false);


//        webSetting.setSupportZoom(true);
    //    webSetting.setDefaultZoom(zoomDensity);
//        webSetting.setBuiltInZoomControls(true);

        //   webSetting.setUseWideViewPort(true);
        //   webSetting.setSupportMultipleWindows(true);
        //增加的地方
        //   webSetting.setLoadWithOverviewMode(true);
        //   webSetting.setAppCacheEnabled(true);
        // webSetting.setDatabaseEnabled(true);
        //  webSetting.setDomStorageEnabled(true);
        // webSetting.setGeolocationEnabled(true);
        //  webSetting.setAppCacheMaxSize(Long.MAX_VALUE);
        // webSetting.setPageCacheCapacity(IX5WebSettings.DEFAULT_CACHE_CAPACITY);
        //  webSetting.setPluginState(WebSettings.PluginState.ON_DEMAND);
        // webSetting.setRenderPriority(WebSettings.RenderPriority.HIGH);
        //  webSetting.setCacheMode(WebSettings.LOAD_NO_CACHE);

        // this.getSettingsExtension().setPageCacheCapacity(IX5WebSettings.DEFAULT_CACHE_CAPACITY);//extension
        // settings 的设计
        webSetting.setLoadWithOverviewMode(true);
        webSetting.setUseWideViewPort(true);

    }


//    @Override
//    protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
//        boolean ret = super.drawChild(canvas, child, drawingTime);
//        return ret;
//    }


}
